{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Example Usage for Series\n",
    "========================"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# remove comment to use latest development version\n",
    "import sys; sys.path.insert(0, '../')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# import libraries\n",
    "import raccoon as rc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Initialize\n",
    "----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "object id: 1924106416536\n",
       "data:\n",
       "[]\n",
       "index:\n",
       "[]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# empty DataFrame\n",
    "srs = rc.Series()\n",
    "srs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "object id: 1924104590056\n",
       "data:\n",
       "[None, None, None]\n",
       "index:\n",
       "[1, 2, 3]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with indexes but no data\n",
    "srs = rc.Series(index=[1, 2, 3])\n",
    "srs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "object id: 1924106418216\n",
       "data:\n",
       "[4, 5, 6]\n",
       "index:\n",
       "[10, 11, 12]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with data\n",
    "srs = rc.Series(data=[4, 5, 6], index=[10, 11, 12])\n",
    "srs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Print\n",
    "-----"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     10        4\n",
      "     11        5\n",
      "     12        6\n"
     ]
    }
   ],
   "source": [
    "srs.print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     10        4\n",
      "     11        5\n",
      "     12        6\n"
     ]
    }
   ],
   "source": [
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Setters and Getters\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'value'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data_name\n",
    "srs.data_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10           4\n",
      "     11           5\n",
      "     12           6\n"
     ]
    }
   ],
   "source": [
    "srs.data_name = 'new_data'\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 11, 12]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# index\n",
    "srs.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index      new_data\n",
      "-------  ----------\n",
      "apple             4\n",
      "pear              5\n",
      "7.7               6\n"
     ]
    }
   ],
   "source": [
    "#indexes can be any non-repeating unique values\n",
    "srs.index = ['apple', 'pear', 7.7]\n",
    "srs.print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10           4\n",
      "     11           5\n",
      "     12           6\n"
     ]
    }
   ],
   "source": [
    "srs.index = [10, 11, 12]\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'index'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the index can also have a name, befault it is \"index\"\n",
    "srs.index_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'units'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srs.index_name = 'units'\n",
    "srs.index_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 5, 6]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data is a shallow copy, be careful on how this is used\n",
    "srs.index_name = 'index'\n",
    "srs.data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Select Index\n",
    "------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[False, True, False]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srs.select_index(11)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Set Values\n",
    "----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10         100\n",
      "     11           5\n",
      "     12           6\n"
     ]
    }
   ],
   "source": [
    "# set a single cell\n",
    "srs.set(10, 100)\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10         100\n",
      "     11           5\n",
      "     12           6\n",
      "     13           9\n"
     ]
    }
   ],
   "source": [
    "# set a value outside current range creates a new row. Can also use [] for setting\n",
    "srs[13] = 9\n",
    "srs.print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          66\n",
      "     11           5\n",
      "     12          66\n",
      "     13           9\n"
     ]
    }
   ],
   "source": [
    "# set a subset of rows\n",
    "srs[[10, 12]] = 66\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          88\n",
      "     11           5\n",
      "     12          99\n",
      "     13           9\n"
     ]
    }
   ],
   "source": [
    "# using boolean list\n",
    "srs.set([True, False, True, False], [88, 99])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          88\n",
      "     11           5\n",
      "     12          33\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "# setting with slices\n",
    "srs[12:13] = 33\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10           1\n",
      "     11           2\n",
      "     12           3\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "srs[10:12] = [1, 2, 3]\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10           1\n",
      "     11          22\n",
      "     12           3\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "# set a location\n",
    "srs.set_location(1, 22)\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "# set multiple locations\n",
    "srs.set_locations([0, 2], [11, 27])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n",
      "     14          99\n"
     ]
    }
   ],
   "source": [
    "# append a row, DANGEROUS as there is not validation checking, but can be used for speed\n",
    "srs.append_row(14, 99)\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n",
      "     14          99\n",
      "     15         100\n",
      "     16         110\n"
     ]
    }
   ],
   "source": [
    "# append multiple rows, again no sort check\n",
    "srs.append_rows([15, 16], [100, 110])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Get Values\n",
    "----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get a single cell\n",
    "srs[10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "# get subset of the index\n",
    "srs[[11, 12, 13]].print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n"
     ]
    }
   ],
   "source": [
    "# get using slices\n",
    "srs[11:13].print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[22, 27, 33]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# return as a list\n",
    "srs.get([11, 12, 13], as_list=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Set and Get by Location\n",
    "-----------------------\n",
    "Locations are the index of the index, in other words the index locations from 0...len(index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'index': 12, 'new_data': 27}\n"
     ]
    }
   ],
   "source": [
    "print(srs.get_location(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'index': 16, 'new_data': 110}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srs.get_location(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     12          27\n"
     ]
    }
   ],
   "source": [
    "srs.get_locations(locations=[0, 2]).print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 27]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srs.get_locations(locations=[0, 2], as_list=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     11          22\n",
      "     12          27\n",
      "     13          33\n",
      "     14          99\n",
      "     15           9\n",
      "     16          10\n"
     ]
    }
   ],
   "source": [
    "srs.set_locations([-1, -2], values=[10, 9])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Head and Tail\n",
    "-------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     10          11\n",
      "     11          22\n"
     ]
    }
   ],
   "source": [
    "srs.head(2).print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     15           9\n",
      "     16          10\n"
     ]
    }
   ],
   "source": [
    "srs.tail(2).print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Delete rows\n",
    "-------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    new_data\n",
      "-------  ----------\n",
      "     11          22\n",
      "     12          27\n",
      "     14          99\n",
      "     15           9\n",
      "     16          10\n"
     ]
    }
   ],
   "source": [
    "srs.delete([10, 13])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Convert\n",
    "-------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'index': [11, 12, 14, 15, 16], 'new_data': [22, 27, 99, 9, 10]}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# return a dict\n",
    "srs.to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'new_data': [22, 27, 99, 9, 10]}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# exclude the index\n",
    "srs.to_dict(index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrderedDict([('index', [11, 12, 14, 15, 16]),\n",
       "             ('new_data', [22, 27, 99, 9, 10])])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# return an OrderedDict()\n",
    "srs.to_dict(ordered=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Sort by Index\n",
    "---------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     25        6\n",
      "     24        7\n",
      "     23        8\n",
      "     22        9\n"
     ]
    }
   ],
   "source": [
    "srs = rc.Series([6, 7, 8, 9], index=[25, 24, 23, 22])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     22        9\n",
      "     23        8\n",
      "     24        7\n",
      "     25        6\n"
     ]
    }
   ],
   "source": [
    "# sort by index. Sorts are inplace\n",
    "srs.sort_index()\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Math Methods\n",
    "------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "srs = rc.Series([1, 2, 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[False, False, True]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# test for equality\n",
    "srs.equality(value=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, False]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# all math methods can operate on a subset of the index\n",
    "srs.equality(indexes=[1, 2], value=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Multi-Index\n",
    "-----------\n",
    "Raccoon does not have true hierarchical mulit-index capabilities like Pandas, but attempts to mimic some of the capabilities with the use of tuples as the index. Raccoon does not provide any checking to make sure the indexes are all the same length or\n",
    "any other integrity checking."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index          value\n",
      "-----------  -------\n",
      "('a', 1, 3)        1\n",
      "('a', 1, 4)        2\n",
      "('a', 2, 3)        3\n",
      "('b', 1, 4)        4\n",
      "('b', 2, 1)        5\n",
      "('b', 3, 3)        6\n"
     ]
    }
   ],
   "source": [
    "tuples = [('a', 1, 3), ('a', 1, 4), ('a', 2, 3), ('b', 1, 4), ('b', 2, 1), ('b', 3, 3)]\n",
    "srs = rc.Series([1, 2, 3, 4, 5, 6], index=tuples)\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "The select_index method works with tuples by allowing the * to act as a wild card for matching."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, True, True, False, False, False]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare = ('a', None, None)\n",
    "srs.select_index(compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, False, True, False, False, False]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare = ('a', None, 3)\n",
    "srs.select_index(compare, 'boolean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 2, 3), ('b', 2, 1)]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare = (None, 2, None)\n",
    "srs.select_index(compare, 'value')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 1, 3), ('a', 2, 3), ('b', 3, 3)]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare = (None, None, 3)\n",
    "srs.select_index(compare, 'value')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, True, True, True, True, True]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare = (None, None, None)\n",
    "srs.select_index(compare)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Reset Index\n",
    "-----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "      9        1\n",
      "     10        2\n",
      "     11        3\n"
     ]
    }
   ],
   "source": [
    "srs = rc.Series([1, 2, 3], index=[9, 10, 11])\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "object id: 1924106640744\n",
       "data:\n",
       "[1, 2, 3]\n",
       "index:\n",
       "[0, 1, 2]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srs.reset_index()\n",
    "srs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  new name    value\n",
      "----------  -------\n",
      "         9        1\n",
      "        10        2\n",
      "        11        3\n"
     ]
    }
   ],
   "source": [
    "srs = rc.Series([1, 2, 3], index=[9, 10, 11], index_name='new name')\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "      0        1\n",
      "      1        2\n",
      "      2        3\n"
     ]
    }
   ],
   "source": [
    "srs.reset_index()\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Sorted Series\n",
    "-----------------\n",
    "Series will be set to sorted by default if no index is given at initialization. If an index is given at initialization then the parameter sorted must be set to True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "srs = rc.Series([3, 5, 4], index=[12, 15, 14], sort=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "When sorted=True on initialization the data will be sorted by index to start"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     12        3\n",
      "     14        4\n",
      "     15        5\n"
     ]
    }
   ],
   "source": [
    "srs.print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     12        3\n",
      "     14        4\n",
      "     15        5\n",
      "     16        9\n"
     ]
    }
   ],
   "source": [
    "srs[16] = 9\n",
    "print(srs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  index    value\n",
      "-------  -------\n",
      "     12      3\n",
      "     13      3.5\n",
      "     14      4\n",
      "     15      5\n",
      "     16      9\n"
     ]
    }
   ],
   "source": [
    "srs.set(indexes=13, values=3.5)\n",
    "print(srs)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:.conda-raccoon]",
   "language": "python",
   "name": "conda-env-.conda-raccoon-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
